xm-test: 10_block_attach_detach_multiple_devices fixed
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 5 Aug 2009 12:36:24 +0000 (13:36 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 5 Aug 2009 12:36:24 +0000 (13:36 +0100)
This patch fixes and (re-)enables test 10 of the block-create suite.
The tests by random attach and detach devices to / from a domU and
checks if everything is ok.

Signed-off-by: Andreas Florath <xen@flonatel.org>
tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py
tools/xm-test/tests/block-create/Makefile.am

index 3ac6078388cdbd43a0f6193d9715caa05abefab2..58c70673f7b493a79d6b6bcc528ab76972aff852 100644 (file)
@@ -1,40 +1,42 @@
 #!/usr/bin/python
 
 # Copyright (C) International Business Machines Corp., 2005
-# Author: Murillo F. Bernardes <mfb@br.ibm.com>
+# Copyright (C) flonatel GmbH & Co. KG, 2009
+# Authors: Murillo F. Bernardes <mfb@br.ibm.com>
+#          Andreas Florath <xen@flonatel.org>
+
+# Block devices are by random attached to and detached from the domU. 
 
 import re
 import random
 from xen.util import blkif
 
-from os import path.basename
+from os.path import basename
 
 from XmTestLib import *
 from XmTestLib.block_utils import *
 
 def availableRamdisks():
-    i = 0
-    while os.access("/dev/ram%d" % i, os.F_OK ):
-        i += 1
-
-    return i
+    i=0
+    while os.access("/dev/ram%d" % i, os.F_OK):
+        i+=1
+    return i-1
 
 def attach(phy, devname):
     block_attach(domain, "phy:%s" % phy, devname)
     run = console.runCmd("cat /proc/partitions")
     if not re.search(basename(devname), run["output"]):
-        return -2, "Failed to attach block device: /proc/partitions does not show that!"
-
+        return -2, "Failed to attach block device: " \
+                   + "/proc/partitions does not show that!"
     return 0, None
 
 
 def detach(devname):
     block_detach(domain, devname)
-
     run = console.runCmd("cat /proc/partitions")
     if re.search(basename(devname), run["output"]):
-        return -2, "Failed to detach block device: /proc/partitions still showing that!"
-
+        return -2, "Failed to detach block device: " \
+                   + "/proc/partitions still showing that!"
     return 0, None
     
 if ENABLE_HVM_SUPPORT:
@@ -58,34 +60,39 @@ try:
 except ConsoleError, e:
     saveLog(console.getHistory())
     FAIL(str(e))
-    
 
-ramdisks = availableRamdisks()-1
-print "ramdisks=%d" % ramdisks
-i = 0 
-devices = []
+ramdisk_cnt = availableRamdisks()
 
-while i < ramdisks or devices:
-    op = random.randint(0,1) # 1 = attach, 0 = detach
-    if (not devices or op) and i < ramdisks:
-        i += 1
-    devname = "/dev/xvda%d" % i
-    phy = "/dev/ram%d" % i
-    print "Attaching %s to %s" % (devname, phy)
-    status, msg = attach( phy, devname )
+detached = range(0, ramdisk_cnt)
+attached = []
+
+def attach_device():
+    n = random.choice(detached)
+    status, msg = attach("ram%d" % n, "xvda%d" % n)
     if status:
         FAIL(msg)
-    else:
-        devices.append(devname)
+    detached.remove(n)
+    attached.append(n)
 
-    elif devices:
-        devname = random.choice(devices)
-    devices.remove(devname)
-    print "Detaching %s" % devname
-    status, msg = detach(devname)
+def detach_device():
+    n = random.choice(attached)
+    status, msg = detach("xvda%d" % n)
     if status:
         FAIL(msg)
+    detached.append(n)
+    attached.append(n)
+
+# First attach some
+for i in xrange(0, ramdisk_cnt/2):
+    attach_device()
 
+for i in xrange(0, ramdisk_cnt*5):
+    op = random.randint(0,1) # 1 = attach, 0 = detach
+    if op:
+        detach_device()
+    else:
+        attach_device()
+    
 # Close the console
 domain.closeConsole()
 
index 7459cb9f490a55cf508964f5b1c0686588f81bd7..c9b41f6f3da4b5f1a2308fa25552ab661661a403 100644 (file)
@@ -9,6 +9,7 @@ TESTS = 01_block_attach_device_pos.test  \
        07_block_attach_baddevice_neg.test \
        08_block_attach_bad_filedevice_neg.test \
        09_block_attach_and_dettach_device_check_data_pos.test \
+       10_block_attach_dettach_multiple_devices.test \
        11_block_attach_shared_dom0.test \
        12_block_attach_shared_domU.test